<?php 
session_start();
include('databaseconnection.php');
$email=$_SESSION['email'];
$result=mysql_query("SELECT * FROM system_user WHERE email='$email'");
if(!$result) echo "invalid";

if(mysql_num_rows($result) == 1) 
{
$dd=gmdate(DATE_ATOM,time());
			$d=explode("T",$dd);
			$date=$d[0];
$result2 = mysql_query("SELECT * FROM user WHERE email='$email' ");
	while($row=mysql_fetch_array($result2))
	{
		$username=$row['first_name'];
	}

	  if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
if (file_exists("Upload/" . $_FILES["file"]["name"]))
      {
     header("Location:addterm.php?msg= File name already exists.........");
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],"Upload/" . $_FILES["file"]["name"]);
	  	$handle = @fopen('Upload/'.$_FILES["file"]["name"], "r");
	  	while (($buffer = fgets($handle)) !== false) {
		$items =str_replace(",","','",$buffer);
		$val=explode("','",$items);
		$accepted_meaning=$val[2];	
		$term=$val[0];	
		$resulte=mysql_query("select * from terms where term='$term' and accepted_meaning='$accepted_meaning'");
		if(mysql_num_rows($resulte) == 1) 
		{
			header("Location:addterm.php?msg= Some Term and Accepted meaning are already exist.....");
		}
		else
		{
			$sql="INSERT INTO terms (term,domain,accepted_meaning,language) VALUES('".$items."')";   		
			mysql_query($sql);
		}
		//echo mysql_error();
		}
		fclose($handle);
		if(mysql_affected_rows()>0)
		{
		 header("Location:addterm.php?msg= File is added.........");
		}

	  }
	  	
    mysql_query("UPDATE terms SET suggested_date = '$date',accepted_date='$date', suggested_by='$username', checked_by='$username'
WHERE suggested_by=''");
 mysql_close($con);
}
else
{
header("Location:addterm.php?msg=administrator only allow to add term....you can suggest term");
}
?> 